package servlet;

import java.io.IOException;
import java.util.List;

import javax.print.attribute.standard.RequestingUserName;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.yunhe.dao.BoardDao;
import cn.yunhe.dao.TopicDao;
import cn.yunhe.dao.impl.BoardDaoImpl;
import cn.yunhe.dao.impl.TopicDaoImpl;
import cn.yunhe.entity.Board;
import cn.yunhe.entity.Topic;

/**
 * Servlet implementation class TopicServlet
 */
@WebServlet("/TopicServlet")
public class TopicServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public TopicServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

		TopicDao td=new TopicDaoImpl();
		BoardDao boardDao=new  BoardDaoImpl();
		String bidStr=request.getParameter("bid");
			//System.out.println("================"+bidStr);
		int bid=1;
		if(bidStr!=null && !bidStr.trim().equals("")){
			bid=Integer.parseInt(bidStr);
			System.out.println("======nihao========");
		}
			Board board  =  boardDao.getBoardById(bid);
			List<Topic> tlist=td.findTopicsByBoardId(bid);
			request.setAttribute("tlist", tlist);
			request.setAttribute("bid", bid);
			request.getRequestDispatcher("rightMenu.jsp").forward(request, response);
	}
	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
